﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Mundo_3D
{
    enum Tipo_Modelo {modelo,plataforma};

    class Modelo_Basico
    {
        public Model model { get; protected set; }
        public Matrix world = Matrix.CreateWorld(new Vector3(1.0f, 1.1f, 1.0f), Vector3.Forward, Vector3.Up);
        public Matrix worldTranslation = Matrix.CreateWorld(new Vector3(1.0f, 1.1f, 1.0f), Vector3.Forward, Vector3.Up);
        public Matrix worldRotation = Matrix.Identity;
        public Tipo_Modelo tipo;
        public Texture2D textura;

        public Modelo_Basico(Model m, Tipo_Modelo tip, Texture2D tex)
        {
            model = m;
            tipo = tip;
            textura = tex;
        }

        public Modelo_Basico(Model m, Tipo_Modelo tip, Matrix w, Texture2D tex)
        {
            model = m;
            tipo = tip;
            world = w;
            textura = tex;
        }

        public virtual void Update()
        {

        }

        public void Draw(Camara_Basica camera)
        {
            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect be in mesh.Effects)
                {
                    be.TextureEnabled = true;
                    be.Texture = textura;
                    be.EnableDefaultLighting();
                    be.Projection = camera.projection;
                    be.View = camera.view;
                    be.World = Matrix.CreateScale(5.0f) * GetWorld() * mesh.ParentBone.Transform;
                    
                }
                mesh.Draw();
            }
        }

        public virtual Matrix GetWorld()
        {
            return world;
        }

        public Tipo_Modelo getTipo()
        {
            return tipo;
        }
    }
}
